<?php
/**
 * Created by jinqiang on 2024/7/4 11:15.
 * Copyright (c) 2024, Your Company. All rights reserved.
 */


namespace App\Http\Controllers\Produce;


use App\Http\Controllers\Controller;
use App\Http\Services\Produce\BatchService;
use Illuminate\Http\Request;

class BatchController extends Controller
{
    public function list(Request $request, BatchService $batchService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $batchService->search($param);
        return result($res);
    }

    public function status(Request $request, BatchService $batchService)
    {
        $this->validate($request, [
            'id' => 'required',
            'status' => 'required'
        ]);
        $param = $request->all();
        $res = $batchService->setStatus($param['id'], $param['status']);
        return $res['code'] === 0 ? success("操作成功") : error($res['msg'], $res);
    }

    public function save(Request $request, BatchService $batchService)
    {
        $this->validate($request, [
            'batch_title' => 'required',
            'batch_date' => 'required'
        ]);
        $param = $request->all();
        $res = $batchService->save($param);
        return $res['code'] === 0 ? success("操作成功") : error($res['msg'], $res);
    }
}
